import { createRouter, createWebHashHistory, RouteLocationNormalized, RouteRecordRaw, RouterOptions } from 'vue-router'
import Home from './views/Home.vue'
import User from './views/User/index.vue'
import questionindex from './views/Question/questionindex.vue'
import questionmatch from './views/Question/questionmatch.vue'
import questiontype from './views/Question/questiontype.vue'
import questionbankindex from './views/Questionbank/questionbankindex.vue'
import questionbank from './views/Questionbank/questionbank.vue'
import activity from './views/Activity/activity.vue'
import activityindex from './views/Activity/index.vue'
import articleindex from './views/Article/index.vue'
import article from './views/Article/article.vue'
import match from './views/match/index.vue'
import matchindex from './views/match/matchindex.vue'
import matchquestion from './views/match/matchquestion.vue'
import matchend from './views/match/matchend.vue'
import TEam from './views/team/index.vue'
import TEamdynamic from './views/team/dynamic.vue'
import TEammatch from './views/team/match.vue'
import TEamquestion from './views/team/question.vue'
import TEamquestionbank from './views/team/questionbank.vue'
import TEamsett from './views/team/sett.vue'
import TEamtask from './views/team/task.vue'
import TEamnotice from './views/team/notice.vue'
import TEamuser from './views/team/user.vue'
import TEamdata from './views/team/data.vue'
import Mydata from './views/User/mydata.vue'
import Myquestionbank from './views/User/questionbank.vue'
import Myquestion from './views/User/question.vue'
import Mychangequestion from './views/User/questionindex.vue'
import Mychangequestionbank from './views/User/questionbankindex.vue'
import Myaddteam from './views/User/myaddteam.vue'
import Userqustion from './views/userquestion/index.vue'
import Mynotice from './views/notice/index.vue'
import Mytest from './views/test/index.vue'
import testindex from './views/test/testindex.vue'
import testquestion from './views/test/testquestion.vue'
import testend from './views/test/testend.vue'
import Logs from './views/logs/index.vue'
import Activitydata from './views/Activity/activitydata.vue'
import usertestcase from './views/Question/watchtestcase.vue'
import Chart from './views/team/chart.vue'
import Rank from './views/team/rank.vue'
import Data2 from './views/team/data2.vue'
import Teamuserdata from './views/team/teamuserdata.vue'
import Teamdata from './views/team/Teamdata.vue'
import TeamMatcdatahVue from './views/team/matchdata.vue'
import { jilurizhi } from '../api'
import TeamcreatedActivity from './views/team/createdactivit.vue'
import TEamjob from './views/team/teamjob.vue'
import Createdteamjob from './views/team/createdteamjob.vue'
import questionLeaderboardVue from './views/team/questionLeaderboard.vue'
import Submission from './views/Question/Submission.vue'
import testcases from './views/Question/testcases.vue'
import Questioncontext from './views/Question/context.vue'
import discuss from './views/Question/discuss.vue'
import usersolution from './views/Question/usersolution.vue'
import integral from './views/User/integral.vue'
import integralreward from './views/User/integralreward.vue'
import teamfile from './views/team/oss.vue'
import activityquestionVue from './views/Activity/activityquestion.vue'

function toID(rote: RouteLocationNormalized): Record<string, any> {
  return {
    ID: Number(rote.params.ID)
  }
}

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: '首页',
    component: Home
  },
  {
    path: '/userqustion',
    name: '答题记录',
    component: Userqustion
  },
  {
    path: '/mydata',
    name: '我的资源',
    component: Mydata,
    redirect: {
      name: '我的题库'
    },
    children: [
      {
        path: 'question',
        name: '我的题库',
        component: Myquestion,
      },
      {
        path: 'questionbank',
        name: '我的题单',
        component: Myquestionbank,
      },
      {
        path: 'changequestionbank/:ID',
        name: '修改我的题单',
        component: Mychangequestionbank,
        props: toID
      },
      {
        path: 'changequestion',
        name: '修改我的题库',
        component: Mychangequestion,
      },
      {
        path: 'myaddteam/:ID',
        name: '加入团队',
        component: Myaddteam,
        props: toID
      },
    ]
  },
  {
    path: '/usertestcase',
    name: '贡献测试点查询',
    component: usertestcase
  },
  {
    path: '/question',
    name: '题库',
    component: questionindex
  },
  {
    path: '/activityquestion/:ID',
    name: '比赛题目',
    component: activityquestionVue,
    props: toID,

  },
  {
    path: '/question/:ID',
    name: '题目',
    component: questiontype,
    props: toID,
    children: [
      // {
      //   path: 'Questioncontext',
      //   name: '题目详情',
      //   component: Questioncontext
      // },
      {
        path: 'Submission',
        name: '我的提交',
        component: Submission
      },
      {
        path: 'discuss',
        name: '问题讨论',
        component: discuss
      },
      {
        path: 'testcases',
        name: '贡献测试点',
        component: testcases
      },
      {
        path: 'usersolution',
        name: '题目题解',
        component: usersolution
      },
    ]
  },
  {
    path: '/questionbank/:ID',
    name: '题库列表',
    component: questionbank,
    props: toID
  },
  {
    path: '/questionbank',
    name: '题单',
    component: questionbankindex
  },
  {
    path: '/activity',
    name: '竞赛',
    component: activityindex
  },
  {
    path: '/activity/:ID',
    name: '比赛详情',
    component: activity,
    props: toID
  },
  {
    path: '/activitydata/:ID',
    name: '比赛数据详情',
    component: Activitydata,
    props: toID

  },
  {
    path: '/article/:ID',
    name: '动态详情',
    component: article,
    props: toID
  },
  {
    path: '/article',
    name: '动态',
    component: articleindex
  },
  {
    path: '/user',
    name: '用户',
    component: User,
  },
  {
    path: '/integral',
    name: '积分',
    component: integral,
  },
  {
    path: '/integralreward',
    name: '积分兑换',
    component: integralreward,
  },
  {
    path: '/notice',
    name: '我的通知',
    component: Mynotice,
  },

  {
    path: '/chart/:ID',
    name: '团队数据图标',
    component: Chart,
    props: toID,
  },
  {
    path: '/test/:ID',
    name: '测评',
    component: Mytest,
    props: toID,
    redirect: {
      name: '测评首页'
    },
    children: [
      {
        name: '测评首页',
        path: 'index',
        component: testindex,
      },
      {
        name: '测评答题',
        path: 'question/:index',
        component: testquestion,
        props: true
      },
      {
        name: '测评结束',
        path: 'testend',
        component: testend,
      }
    ]
  },
  {
    path: '/match/:ID',
    name: '比赛',
    component: match,
    redirect: {
      name: '比赛首页'
    },
    props: toID,


    children: [
      {
        name: '比赛首页',
        path: 'index',
        component: matchindex,
      },
      {
        name: '比赛答题',
        path: 'question/:index',
        component: matchquestion,
        props: true
      },
      {
        name: '比赛结束',
        path: 'matchend',
        component: matchend,
      }
    ]
  },
  {
    path: '/teamactivity/:ID',
    name: '创建比赛',
    component: TeamcreatedActivity,
    props: toID,
  },
  {
    path: '/createdteamjob/:ID',
    name: '创建工作',
    component: Createdteamjob,
    props: toID,
  },
  {
    path: '/team/:ID',
    name: '团队',
    component: TEam,
    props: toID,
    redirect: {
      name: '团队动态'
    },
    children: [
      {
        path: 'question',
        name: '团队题目',
        component: TEamquestion,
      },
      {
        path: 'questionbank',
        name: '团队题单',
        component: TEamquestionbank,
      },
      {
        path: 'match',
        name: '团队比赛',
        component: TEammatch,
      },
      {
        path: 'dynamic',
        name: '团队动态',
        component: TEamdynamic,
      },
      {
        path: 'teamfile',
        name: '团队文件',
        component: teamfile,
      },
      {
        path: 'teamdata',
        name: '团队数据',
        component: TEamdata,
        redirect: {
          name: '成员排行榜'
        },
        // redirect: to => {
        //   console.log(to)
        //   // 方法接收目标路由作为参数
        //   // return 重定向的字符串路径/路径对象
        //   return { path: '/', query: { q: to.params.searchText } }
        // },
        children: [
          {
            path: 'rank',
            name: '成员排行榜',
            component: Rank,
          },
          {
            path: 'questionLeaderboard',
            name: '题目排行榜',
            component: questionLeaderboardVue
          },
          {
            path: 'questiondata',
            name: '成员测评记录',
            component: Data2,
          },
          {
            path: 'teamuserdata',
            name: '成员数据统计',
            component: Teamuserdata,
          },
          {
            path: 'teammatchdata',
            name: '成员比赛记录',
            component: TeamMatcdatahVue,
          },
        ]
      },
      {
        path: 'sett',
        name: '团队设置',
        component: TEamsett,
      },
      {
        path: 'task',
        name: '团队任务',
        component: TEamtask,
      },
      {
        path: 'job',
        name: '团队工作',
        component: TEamjob,
      },
      {
        path: 'teamnotice',
        name: '团队通知',
        component: TEamnotice,
      },
      {
        path: 'user',
        name: '团队组员',
        component: TEamuser,
      },
    ]
  },
  {
    path: '/logs',
    name: 'logs',
    component: Logs
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,

})

router.afterEach((to, from) => {
  const arr: [string, string][] = []
  arr[0] = ['type', 'router']
  arr[1] = ['typename1', to.name ? String(to.name) : '']
  arr[2] = ['__from__', from.name ? String(from.name) : '']
  jilurizhi(arr)
})

export default router
